package com.qf.work;

import com.qf.util.ConnUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    public static final String QUEUE_NAME = "work";

    @Test
    public void publish() throws Exception {
        //1. 获取连接对象..
        Connection conn = ConnUtil.getConn();
        //2. 创建管道
        Channel channel = conn.createChannel();
        //3. 创建队列.
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);
        //4. 发送消息(10条)
        for (int i = 0; i < 10; i++) {
            String msg = "Hello Work " + i;
            channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
        }
        System.out.println("10条消息发送完毕!!!");

        //5. 释放资源
        channel.close();
        conn.close();
    }


}
